home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 10
/
FM Towns Free Software Collection 10.iso
/
ms_dos
/
tool
/
fapxtool
/
src
/
txl
/
txlrtn.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-02-11
|
2KB
|
120 lines
/***************
*
* g:\exe\txl\src\txlrtn.c
*/
#include "txl.h"
void markrtnlist(unsigned int *dlst, unsigned int maxno, FILE *fp)
{
int i = 0, listno;
while (!feof(fp)) {
fgets(line1, 80, fp);
if (sscanf(line1 + 1, "%d", &listno)) {
while (dlst[i] < listno) {
i++;
}
if (dlst[i] == listno) {
if (*(line1) == '+') {
*(line1) = ' ';
}
else {
*(line1) = '+';
}
}
}
fputs(line1, fpmes);
}
}
unsigned int readnum(unsigned int base,unsigned int *dlst, char *str)
{
unsigned int i = base;
char *tmp = str;
while (strchr(tmp, ',') != NULL) {
sscanf(tmp, "%d", &(dlst[i]));
i++;
i &= 8191; /* 念の為ループ */
tmp = strchr(tmp, ',') + 1;
}
sscanf(tmp, "%d", &(dlst[i]));
return (i + 1);
}
unsigned int readnumfile(unsigned int *dlst, char *fname)
{
FILE *fp;
unsigned int i = 0;
if ((fp = fopen(fname, "rt")) == NULL) {
fprintf(stderr, "TXL:can't open '%s'", fname);
Exit(1);
}
while (!feof(fp)) {
fgets(line1, 80, fp);
if (*line1 != '\n') {
i = readnum(i, dlst, line1);
}
}
fclose(fp);
return (i);
}
int cmprtn(unsigned int *x, unsigned int *y)
{
return ((int)((long)(*x) - (long)(*y)));
}
void rtnmark()
{
FILE *fp;
unsigned int *dlst;
unsigned int maxno;
if ((dlst = calloc(8193, sizeof(unsigned int))) == NULL) {
errexit("out of memory");
}
if ((fp = fopen(inputfile, "rt")) == NULL) {
free(dlst);
fprintf(stderr, "TXL:can't open '%s'", inputfile);
Exit(1);
}
fgets(line1, 80, fp);
fputs(line1, fpmes);
fgets(line1, 80, fp);
fputs(line1, fpmes);
fgets(line1, 80, fp);
fputs(line1, fpmes);
fgets(line1, 80, fp);
fputs(line1, fpmes); /* 空読み */
if (*outputfile == '&') {
maxno = readnumfile(dlst, outputfile + 1);
}
else {
maxno = readnum(0, dlst, outputfile);
}
qsort(dlst, maxno, sizeof(unsigned int), cmprtn);
dlst[maxno] = 65535;
markrtnlist(dlst, maxno, fp);
fclose(fp);
free(dlst);
}
void rtninit()
{
fprintf(stderr, "TXL: open RTN_ListMarker\n");
}
void rtndriver(char *val[])
{
rtninit();
outputfile = val[0]; /* & or numbers */
inputfile = val[1]; /* rtn */
rtnmark();
Exit(0);
}